﻿using KeaoBase;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace KeaoMDS.InfoManage
{
    public partial class PeiBiDanGuanLi : BaseForm
    {
        public PeiBiDanGuanLi()
        {
            InitializeComponent();
        }

        private void PeiBiDanGuanLi_Load(object sender, EventArgs e)
        {
            dataGridView1.AutoGenerateColumns = false;
            BindInfo();
        }

        private void BindInfo()
        {
            string createCondition = KeaoUtils._DB.CreateAndCondition("leixing", DataValueCommonType.字符串, "水稳料", "", SearchConditionType.等于);
            if (!string.IsNullOrEmpty(txt_peibidanmingcheng.Text))
            {
                createCondition += KeaoUtils._DB.CreateAndCondition("mingcheng", DataValueCommonType.字符串, txt_peibidanmingcheng.Text, "", SearchConditionType.like);
            }
            DataTable Dt = KeaoUtils._DB.GetDataTableByCondition("tbl_peibidan", createCondition);
            dataGridView1.DataSource = Dt;

        }

        private void dataGridView1_RowStateChanged(object sender, DataGridViewRowStateChangedEventArgs e)
        {
            e.Row.HeaderCell.Value = string.Format("{0}", e.Row.Index + 1);
        }

        private void menu_1_xinzeng_Click(object sender, EventArgs e)
        {
            PeiBiDanBianJi bianji = new PeiBiDanBianJi();
            bianji.ShowDialog();
            BindInfo();
        }

        private void menu_1_xiugai_Click(object sender, EventArgs e)
        {
            if (dataGridView1.SelectedRows.Count == 0)
            {
                return;
            }
            PeiBiDanBianJi peibidanbianji = new PeiBiDanBianJi(dataGridView1.SelectedRows[0], tabControl1.SelectedIndex);
            if (peibidanbianji.ShowDialog() == DialogResult.OK)
            {
                BindInfo();
            }
        }

        private void menu_1_shanchu_Click(object sender, EventArgs e)
        {
            if (tabControl1.SelectedIndex == 0)
            {
                if (dataGridView1.SelectedRows.Count == 0)
                {
                    return;
                }
                if (KeaoUtils.ShowQuestionMessage("确定要删除水稳料配比单信息吗？") == DialogResult.Yes)
                {
                    TableRow delRow = new TableRow() { TableName = "tbl_peibidan", ID = string.Format("{0}", dataGridView1.SelectedRows[0].Cells["col_shuiwenliao_id"].Value) };
                    if (KeaoUtils._DB.DeleteRowByID(delRow) > 0)
                    {
                        BindInfo();
                    }
                }
            }
        }

        private void btn_search_Click(object sender, EventArgs e)
        {
            BindInfo();
        }
    }
}
